package com.jt.spring;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TimerAspect {

    @Pointcut("execution(* cn.tedu.controller.*.*(..))")
    public void pointcut(){}

    @Before("pointcut()")
    public void beforeMethod(JoinPoint joinPoint){
        System.out.println("我是前置通知~~~");
    }

    @After("pointcut()")
    public void afterMethod(JoinPoint joinPoint){
        System.out.println("我是后置通知~~~");
    }

    @Around("pointcut()")
    public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("我是环绕通知开始~~~");
        long begin = System.currentTimeMillis();
        Object obj = joinPoint.proceed();
        long end = System.currentTimeMillis();
        System.out.println(end - begin);
        System.out.println("我是环绕通知结束~~~");
        return obj;
    }
}














